package com.datamanage.asset.repository;

import com.datamanage.asset.entity.Dataset;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface DatasetRepository extends JpaRepository<Dataset, Long> {
    
    @Query("SELECT d FROM Dataset d WHERE d.companyId = :companyId AND d.isDeleted = false")
    Page<Dataset> findByCompanyId(@Param("companyId") Long companyId, Pageable pageable);
    
    @Query("SELECT d FROM Dataset d WHERE d.companyId = :companyId AND d.createdBy = :userId AND d.isDeleted = false")
    Page<Dataset> findByCompanyIdAndUserId(@Param("companyId") Long companyId, @Param("userId") Long userId, Pageable pageable);
    
    @Query("SELECT d FROM Dataset d WHERE d.companyId = :companyId AND d.id = :id AND d.isDeleted = false")
    Optional<Dataset> findByCompanyIdAndId(@Param("companyId") Long companyId, @Param("id") Long id);
    
    @Query("SELECT d FROM Dataset d WHERE d.companyId = :companyId AND d.datasetType = :datasetType AND d.isDeleted = false")
    Page<Dataset> findByCompanyIdAndDatasetType(@Param("companyId") Long companyId, @Param("datasetType") String datasetType, Pageable pageable);
    
    List<Dataset> findByCreatedByAndIsDeletedFalse(Long createdBy);
}